home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp95 / freyja_t.z / freyja_t / smjaguar.c < prev    next >
C/C++ Source or Header  |  1992-04-14  |  20KB  |  892 lines

  1. /* SMJAGUAR.C -- HP95LX (Jaguar) Commands and Support, System-Manager Compliant
  2.  
  3.     Written March 1992 by Craig A. Finseth
  4.     Copyright 1992 by Craig A. Finseth
  5.  
  6. NOTE: This entire file is only compiled and linked on IBM PC (MSDOS)
  7. systems and for the system-manager compliant version.  Therefore, no
  8. #ifdef's are required. */
  9.  
  10. #include "freyja.h"
  11.  
  12. /* The following are excerpts from files Copyright 1990 by
  13. Hewlett-Packard and Copyright 1990 by Lotus Development Corporation. */
  14.  
  15. /* ============================================================ */
  16. /* #include "headers/mdit.h" */
  17.  
  18. typedef struct {
  19.     char    far *m_buffer;    /*  user-supplied edit buffer  */
  20.     int     m_length;         /*  length of buffer  */
  21.     int     m_pos;            /*  current cursor position  */
  22.     int     m_row, m_col;     /*  location of edit area  */
  23.     int     m_nrows, m_ncols; /*  dimensions of edit area  */
  24.     int    m_yoff,m_disprows;/*  current top row, number of rows displayable */
  25.     char    m_ccol;           /*  cursor column  */
  26.     char    m_modified;       /*  1 -> buffer has been modified  */
  27.         char    m_xoff;           /*  1st disp. col (for ticker fields only)*/
  28.         char    wrapflag;         /*  1 -> wordwrap enabled,-1 ticker field */
  29.     int     far *m_line;      /*  pointer to array used for line starts */
  30.                   /*     must be at least m_nrows+1 long */
  31.     char     markon;          /* currenty marking? */
  32.     char    spec_flag;
  33.     int    markst;          /* offset of start of mark, inclusive */
  34.     int    markend;      /* offset of end of mark, inclusive */
  35.         int     m_dispcols;       /*  displayable columns */
  36. } MDITDATA;
  37.  
  38.  
  39. /* ============================================================ */
  40. /* #include "headers/edit.h" */
  41.  
  42. typedef struct {
  43.     int edit_length;     /* current length of the edit buffer */
  44.     char first_time;          /* flag for special processing on first char */
  45.     char spec_flags;    /* bit 0 is tab handling */
  46.          int prompt_window;      /* whether this belongs to the prompt window */
  47.     char far *message_line; /* the top line message for prompt */
  48.     int message_line_length;/* length of same */
  49.     char far *prompt_line;  /* second line of prompt window */
  50.     int prompt_line_length; /* length of same */
  51.     char edit_buffer[80];   /* work space for the buffer */
  52.     int  line_array[2];    /* line array needed by mdit */
  53.     MDITDATA mdit;          /* multi-line edit structure */
  54.     int e_dispcols;
  55. } EDITDATA;
  56.  
  57. /* ============================================================ */
  58. /* #include "headers/event.h" */
  59.  
  60. enum event_kind {
  61.     E_NONE,        /* no events available */
  62.     E_KEY,        /* keystroke available */
  63.     E_BREAK,    /* CNTRL_BREAK encountered */
  64.     E_ACTIV,    /* reactivation event, always follows E_DEACT */
  65.     E_DEACT,    /* about to sleep, next event request is delayed */
  66.     E_TERM,        /* forced closure of application */
  67.     E_BRIDGE,    /* 123 bridge service request, only ret. to 123 */
  68.     E_GROW,         /* request to 123 to grow */
  69.     E_SHRINK,    /* request to 123 to shrink */
  70.     E_ALARM_EXP,    /* application's alarm has expired */
  71.     E_ALARM_DAY,    /* daily chance to set an alarm */
  72.     E_TIMECHANGE    /* system date or time has been changed */
  73. };
  74.  
  75. typedef struct {
  76.     enum event_kind kind;
  77.     unsigned int data;    /* ASCII (CP 850) translation of keystroke */
  78.     unsigned char scan;    /* scan code from BIOS */
  79.     unsigned char shifts;    /* shifts register, when function returns */
  80.                 /* not necessarily when key struck */
  81.     unsigned int lics;    /* LICS translation of keystroke */
  82.     unsigned char fkey_num;    /* function key number for 123 only */
  83.     void far * bridge;    /* pointer to 123 bridge data structure */
  84. } EVENT;
  85.  
  86.  
  87. /* ============================================================ */
  88. /* #include "headers/fmenu.h" */
  89.  
  90. /* define return codes */
  91.  
  92. #define    RET_BADFILE        -5
  93. #define    RET_BADDIR        -4
  94. #define    RET_BADDRIVE    -3
  95. #define    RET_UNKNOWN        -2
  96. #define    RET_BAD            -1
  97. #define    RET_OK            0
  98. #define    RET_REDISPLAY    1
  99. #define    RET_ACCEPT        2
  100. #define    RET_ABORT        3
  101.  
  102. /* file info structures created in FM_BUFFER */
  103. typedef    struct {
  104.     char fi_attr;                /*  file attribute  */
  105.     int fi_time;                /*  time modified  */
  106.          int fi_date;                /*  date modified  */
  107.     long fi_size;                  /*  file length  */
  108.          char fi_name[13];            /*  file name  */
  109. } FILEINFO;                                  
  110.  
  111. /* define the menu structure */
  112. typedef struct {
  113.     char far *fm_path;        /* base directory name C:\DATA\ */
  114.     char far *fm_pattern;        /* file pattern, e.g.  *.WK1    */
  115.     FILEINFO far *fm_buffer;    /* workspace  for file list (hold finfos) */
  116.     int fm_buf_size;        /* size of the buffer in bytes */
  117.          int fm_startline,fm_startcol;    /* starting row,col */
  118.     int fm_numlines, fm_numcols;    /* number of lines and columns */
  119.     int fm_filesperline;        /* nuumber of files displayed across */
  120. /* -- Initted in service -- */
  121.     int fm_firstedit;            /* 0 if first edit char, else multi line */
  122.     int fm_filesinbuf;        /* number of files in list */
  123.     int fm_maxfinbuf;        /* maximum number of files buffer holds */
  124.     int fm_topfile;            /* file at top of list */
  125.     int fm_curselect;        /* index of file to highlight */
  126.     int fm_oldselect;        /* index of file to un-highlight */
  127.     int fm_focus;            /* 1 = fmenu, 2 = edit */
  128. } FMENU;
  129.  
  130.  
  131. /* ============================================================ */
  132. /*#include "headers/menu.h"*/
  133.  
  134. #define   MAX_KWDS    20
  135. #define   MAX_MENU     3
  136. #define   MAX_MWID     80
  137.  
  138. typedef struct {
  139.      char menu_text [MAX_MENU][MAX_MWID];
  140.      int menu_count;
  141.      int menu_highlight;
  142.      int menu_tprompt;
  143.      char menu_line   [MAX_KWDS];
  144.      char menu_offset [MAX_KWDS];
  145.      char menu_length [MAX_KWDS];
  146.      char menu_letter [MAX_KWDS];
  147.     unsigned menu_prompt[MAX_KWDS];
  148.      } MENUDATA;
  149.  
  150.  
  151. /* ============================================================ */
  152. /*#include "headers/settings.h"*/
  153.  
  154. #define MAX_MACRO_LEN    256
  155. #define NAMEBUFLEN    30
  156. #define TITLEBUFLEN    30
  157. #define COMPANYBUFLEN    28
  158.  
  159. /*  settings */
  160. typedef struct {
  161.     int    Country;    /* */
  162.     int    Volume;     /* 1 speaker volume level 0ffh for off and 0-3 */
  163.     int    Contrast;    /* 2 contrast level 1-5 */
  164.     int    WeekStart;    /* 3 week starts SUNDAY or Monday */
  165.     int    Punctuation;    /* 4 Punctuation format */
  166.     int     Language;    /* two character code for current language */
  167.     int    DateFormat;    /* 6 current date format */
  168.     int    TimeFormat;    /* 7 current time format */
  169.     int    Sort;        /* 8 collating sequence */
  170.     char    PicFile[80];    /* picture file name */
  171.     char    Name_Buff[NAMEBUFLEN];    
  172.     char    Title_Buff[TITLEBUFLEN]; 
  173.     char    Company_Buff[COMPANYBUFLEN]; 
  174.     int     LanguageCount;
  175.     int    LanguagesAvail[6];    /* MAX_LANG */
  176.     char    LanguageMenu[66];    
  177.  
  178.     char    DateSeparator[2]; /* date separator  can be /-. */
  179.     char    TimeSeparator[2]; /* time separator can be :., or h (for hms) */
  180.     char    DateOrder;    /* */
  181.     char    Time24;        /* use 24 hour time? */
  182.  
  183.     char    Currency[16];   /* currency string */
  184.     int    CurrencyFix;   /* prefix or sufix */
  185.  
  186.     int    Keyboard;
  187.     int    PrBaud;     /* printer baud rate */
  188.     int    PrDriver;    /* epson, hp, etc, by code */
  189.     int     PrInterface;    /* com 1, etc  */
  190.     int    SystemRupt;        /* sysmgr interupt number - 60 default */
  191.     int    CodePage;        /* for PC based - 437 or 850 based */
  192.     int    ExitKeyCode;    /* for PC based - active exit key */
  193.     int    MenuKeyCode;    /* for PC based - active menu key */
  194.     int    CharKeyCode;    /* for PC based - active CHAR key toggle */
  195.     int    Alarm[6];
  196. } SETTINGS;
  197.  
  198.  
  199. typedef struct {
  200.     char    MacroFK;       /* MacroFunctionKey Number 1-10 0 for not used */
  201.         unsigned char MacroSize;   /* elements in the macro */
  202.         char    CommentString[38]; /* MacroFunctionKey's Comment line */
  203.     unsigned int MacroBody[MAX_MACRO_LEN];
  204. } MACROHD;
  205.  
  206.  
  207. /* ============================================================ */
  208. /* #include "headers/time.h" */
  209. typedef struct {
  210.     int    dt_year;
  211.     char    dt_month;
  212.     char    dt_date;
  213.     char    dt_day;
  214.     char    dt_hour;
  215.     char    dt_minute;
  216.     char    dt_second;
  217.     char    dt_hundreth;
  218. } DTM;
  219.  
  220.  
  221. /* ============================================================ */
  222. /* #include "headers/interfac.h" */
  223.  
  224. #define SC_EVENT    1
  225. #define SC_MENU     2
  226. #define SC_SCREEN    3
  227. #define SC_FILE     5
  228. #define SC_PM        6
  229. #define SC_CB        7
  230. #define SC_DTIME    11
  231. #define SC_MISC     15
  232.  
  233. #define F_M_EVENT    (SC_EVENT * 256) + 0
  234. #define m_event(a)    \
  235.     c_service(F_M_EVENT,(void far *)(a) )
  236.  
  237. #define F_M_NEVENT    (SC_EVENT * 256) + 1
  238. #define m_nevent(a)    \
  239.     c_service(F_M_NEVENT,(void far *)(a))
  240.  
  241. #define F_M_NO_FINI    (SC_EVENT * 256) + 7
  242. #define m_no_fini(a)    \
  243.     c_service(F_M_NO_FINI,(void far *)(a) )
  244.  
  245.  
  246.  
  247. #define F_MENU_SETUP    (SC_MENU * 256) + 0
  248. #define menu_setup(a,b,c,d,e,f,g)    \
  249.     c_service(F_MENU_SETUP,(void far *)(a),(void far *)(b), \
  250.         (c),(d),(void far *)(e),(f),(void far *)(g) )
  251.  
  252. #define F_MENU_DIS    (SC_MENU * 256) + 1
  253. #define menu_dis(a)    \
  254.     c_service(F_MENU_DIS,(void far *)(a))
  255.  
  256. #define F_MENU_ON    (SC_MENU * 256) + 2
  257. #define menu_on(a)    \
  258.     c_service(F_MENU_ON,(void far *)(a))
  259.  
  260. #define F_MENU_OFF    (SC_MENU * 256) + 3
  261. #define menu_off(a)    \
  262.     c_service(F_MENU_OFF,(void far *)(a))
  263.  
  264. #define F_MENU_KEY    (SC_MENU * 256) + 4
  265. #define menu_key(a,b,c) \
  266.     c_service(F_MENU_KEY,(void far *)(a),(b),(void far *)(c))
  267.  
  268. #define F_FMENU_INIT      (SC_MENU * 256) + 5
  269. #define fmenu_init(a,b,c,d,e)      \
  270.     c_service(F_FMENU_INIT,(void far *)(a),(void far *)(b),(char far *)(c),(d),(e))
  271.  
  272. #define F_FMENU_DIS     (SC_MENU * 256) + 6
  273. #define fmenu_dis(a,b)      \
  274.     c_service(F_FMENU_DIS,(void far *)(a),(void far *)(b))
  275.  
  276. #define F_FMENU_KEY     (SC_MENU * 256) + 7
  277. #define fmenu_key(a,b,c) \
  278.     c_service(F_FMENU_KEY,(void far *)(a),(void far *)(b),(c))
  279.  
  280. #define F_FMENU_OFF      (SC_MENU * 256) + 8
  281. #define fmenu_off(a,b)     \
  282.     c_service(F_FMENU_OFF,(void far *)(a),(void far *)(a))
  283.  
  284.  
  285.  
  286. #define F_M_CLEAR    (SC_SCREEN * 256) + 1
  287. #define m_clear(a,b,c,d)         \
  288.     c_service(F_M_CLEAR,a,b,c,d)
  289.  
  290.  
  291.  
  292. #define F_M_GET_SYSDIR    (SC_FILE * 256) + 22
  293. #define m_get_sysdir(a)           \
  294.     c_service(F_M_GET_SYSDIR,(void far *)(a))
  295.  
  296.  
  297.  
  298. #define F_M_INIT    (SC_PM * 256) + 0
  299. #define m_init()    c_service(F_M_INIT)
  300.  
  301. #define F_M_FINI    (SC_PM * 256) + 1
  302. #define m_fini()    c_service(F_M_FINI)
  303.  
  304. #define F_M_LOCK    (SC_PM * 256) + 2
  305. #define m_lock()    c_service(F_M_LOCK)
  306.  
  307. #define F_M_UNLOCK    (SC_PM * 256) + 3
  308. #define m_unlock()    c_service(F_M_UNLOCK)
  309.  
  310.  
  311.  
  312. #define F_M_OPEN_CB    (SC_CB * 256) + 0
  313. #define m_open_cb()        \
  314.     c_service(F_M_OPEN_CB)
  315.  
  316. #define F_M_CLOSE_CB    (SC_CB * 256) + 1
  317. #define m_close_cb()        \
  318.     c_service(F_M_CLOSE_CB)
  319.  
  320. #define F_M_RESET_CB    (SC_CB * 256) + 2
  321. #define m_reset_cb(a)        \
  322.     c_service(F_M_RESET_CB,(void far *)(a))
  323.  
  324. #define F_M_NEW_REP    (SC_CB * 256) + 4
  325. #define m_new_rep(a)         \
  326.     c_service(F_M_NEW_REP,(void far *)(a))
  327.  
  328. #define F_M_FINI_REP    (SC_CB * 256) + 5
  329. #define m_fini_rep()        \
  330.     c_service(F_M_FINI_REP)
  331.  
  332. #define F_M_REP_INDEX    (SC_CB * 256) + 7
  333. #define m_rep_index(a,b,c)    \
  334.     c_service(F_M_REP_INDEX,(void far *)(a),(void far *)(b),(void far *)(c))
  335.  
  336. #define F_M_CB_WRITE    (SC_CB * 256) + 8
  337. #define m_cb_write(a,b)     \
  338.     c_service(F_M_CB_WRITE,(void far *)(a),b)
  339.  
  340. #define F_M_CB_READ    (SC_CB * 256) + 9
  341. #define m_cb_read(a,b,c,d)    \
  342.     c_service(F_M_CB_READ,a,b,(void far *)(c),d)
  343.  
  344.  
  345.  
  346. #define F_M_GETDTM    (SC_DTIME * 256) + 1
  347. #define m_getdtm(a)          \
  348.     c_service(F_M_GETDTM,(void far *)(a))
  349.  
  350. #define F_M_GET_SETTINGS (SC_DTIME *256) +9
  351. #define m_get_settings(a,b)      \
  352.     c_service(F_M_GET_SETTINGS, (void far *)(a),(void far *)(b))
  353.  
  354.  
  355.  
  356. #define F_MESSAGE    (SC_MISC * 256) + 3
  357. #define message(a,b,c,d)           \
  358.     c_service(F_MESSAGE,(void far *)(a),b,(void far *)(c),d)
  359.  
  360. #define F_MSG_OFF    (SC_MISC * 256) + 4
  361. #define msg_off()        \
  362.     c_service(F_MSG_OFF)
  363.  
  364. /* ============================================================ */
  365.  
  366. static MACROHD m;
  367. static int *mac_ptr;
  368. static int mac_len;
  369.  
  370. void J_Char(int which);
  371. FLAG J_Copy(void);
  372. FLAG J_Paste(void);
  373.  
  374. /* ------------------------------------------------------------ */
  375.  
  376. void
  377. JInit(void)
  378.     {
  379.     SETTINGS s;
  380.  
  381.     m_init();
  382.  
  383.     mac_len = 0;
  384.  
  385.     m.MacroFK = 1;
  386.     m_get_settings(&s, &m);
  387.     DSetup(s.WeekStart);
  388.     }
  389.  
  390.  
  391. /* ------------------------------------------------------------ */
  392.  
  393. void
  394. JFini(void)
  395.     {
  396.     m_fini();
  397.     }
  398.  
  399.  
  400. /* ------------------------------------------------------------ */
  401.  
  402. /* End a redisplay. */
  403.  
  404. void
  405. JDisEnd(void)
  406.     {
  407.     JLightOn();
  408.     m_unlock();
  409.     }
  410.  
  411.  
  412. /* ------------------------------------------------------------ */
  413.  
  414. /* Start a redisplay. */
  415.  
  416. void
  417. JDisStart(void)
  418.     {
  419.     m_lock();
  420.     JLightOff();
  421.     }
  422.  
  423.  
  424. /* ------------------------------------------------------------ */
  425.  
  426. /* Return the current date. */
  427.  
  428. void
  429. JGetDate(int *year, int *mon, int *day)
  430.     {
  431.     DTM d;
  432.  
  433.     m_getdtm(&d);
  434.     *year = d.dt_year;
  435.     *mon = d.dt_month - 1;
  436.     *day = d.dt_day;
  437.     }
  438.  
  439.  
  440. /* ------------------------------------------------------------ */
  441.  
  442. /* Returns the default configuration file directory. DNAME must point
  443. to an FNAMEMAX-sized buffer. */
  444.  
  445. void
  446. JGetDir(char *dname)
  447.     {
  448.     m_get_sysdir(dname);
  449.     }
  450.  
  451.  
  452. /* ------------------------------------------------------------ */
  453.  
  454. /* Get a file name using the file getter.  Return True on success or
  455. False on abort. */
  456.  
  457. FLAG
  458. JGetFile(char *prompt, char *fname, FLAG usestar)
  459.     {
  460.     FILEINFO fi[100];
  461.     FMENU f;
  462.     EDITDATA ed;
  463.     EVENT e;
  464.     FLAG isdone = FALSE;
  465.     FLAG ok = TRUE;
  466.     char dn[FNAMEMAX];
  467.     char fn[FNAMEMAX];
  468.     char *cptr;
  469.  
  470.     xstrcpy(dn, fname);
  471.     for (cptr = dn + strlen(dn); cptr > dn; --cptr) {
  472.         if (*cptr == ':' || *cptr == '/' || *cptr == '\\') break;
  473.         }
  474.     if (*cptr == ':' || *cptr == '/' || *cptr == '\\') {
  475.         xstrcpy(fn, cptr + 1);
  476.         *(cptr + 1) = NUL;
  477.         }
  478.     else    {
  479.         xstrcpy(fn, cptr);
  480.         *cptr = NUL;
  481.         }
  482.     if (*fn == NUL || usestar) {
  483.         xstrcpy(fn, "*.*");
  484.         }
  485.  
  486.     f.fm_path = dn;
  487.     f.fm_pattern = fn;
  488.     f.fm_buffer = fi;
  489.     f.fm_buf_size = sizeof(fi);
  490.     f.fm_startline = -2;
  491.     f.fm_startcol = 0;
  492.     f.fm_numlines = 15;
  493.     f.fm_numcols = 40;
  494.     f.fm_filesperline = 3;
  495.  
  496.     ed.prompt_window = 1;
  497.     ed.prompt_line_length = 0;
  498.     ed.message_line = prompt;
  499.     ed.message_line_length = strlen(prompt);
  500.  
  501.     m_clear(-3, 0, 15, 40);
  502.  
  503.     if (fmenu_init(&f, &ed, "", 0, 0) != RET_OK) {
  504.         DError("can't init file getter");
  505.         return(FALSE);
  506.         }
  507.  
  508.     VidCurOff();
  509.     e.kind = E_ACTIV;
  510.     while (!isdone) {
  511.         if (e.kind != E_NONE) fmenu_dis(&f, &ed);
  512.         m_event(&e);
  513.         switch (e.kind) {
  514.  
  515.         case E_ACTIV:
  516.             DNewDisplay();
  517.             DIncrDisplay();
  518.             break;
  519.  
  520.         case E_TERM:
  521.             mac_len = 1;
  522.             mac_ptr = (int *)(m.MacroBody);
  523.             m.MacroBody[0] = KEYQUIT;
  524.             isdone = TRUE;
  525.             break;
  526.         
  527.         case E_BREAK:
  528.             ok = FALSE;
  529.             isdone = TRUE;
  530.             break;
  531.  
  532.         case E_KEY:
  533.             if (e.data == ESC || e.data == BEL) {
  534.                 ok = FALSE;
  535.                 isdone = TRUE;
  536.                 }
  537.             else    {
  538.                 switch (fmenu_key(&f, &ed, e.data)) {
  539.  
  540.                 case RET_UNKNOWN:
  541.                 case RET_BAD:
  542.                     TBell();
  543.                     break;
  544.  
  545.                 case RET_OK:
  546.                     break;
  547.  
  548.                 case RET_REDISPLAY:
  549.                     DModeLine();
  550.                     break;
  551.  
  552.                 case RET_ACCEPT:
  553.                     isdone = TRUE;
  554.                     break;
  555.  
  556.                 case RET_ABORT:
  557.                     ok = FALSE;
  558.                     isdone = TRUE;
  559.                     break;
  560.                     }
  561.                 }
  562.             break;
  563.             }
  564.         }
  565.  
  566.     fmenu_off(&f, &ed);
  567.     VidCurOn();
  568.     DNewDisplay();
  569.     xstrcpy(fname, ed.edit_buffer);
  570.     return(ok);
  571.     }
  572.  
  573.  
  574. /* ------------------------------------------------------------ */
  575.  
  576. /* Get a key and handle Jaguar-specific translation. */
  577.  
  578. int
  579. JGetKey(void)
  580.     {
  581.     int chr;
  582.     EVENT e;
  583.  
  584. again:
  585.     if (mac_len > 0) {
  586.         mac_len--;
  587.         chr = *mac_ptr++;
  588.         }
  589.     else    {
  590.         for (chr = KEYNONE; chr == KEYNONE; ) {
  591.             m_event(&e);
  592.             switch (e.kind) {
  593.  
  594.             case E_ACTIV:
  595.                 DNewDisplay();
  596.                 DIncrDisplay();
  597.                 VidCurOn();
  598.                 break;
  599.  
  600.             case E_TERM:
  601.                 chr = KEYQUIT;
  602.                 break;
  603.  
  604.             case E_BREAK:
  605.                 chr = KEYABORT;
  606.                 break;
  607.  
  608.             case E_KEY:
  609.                 chr = e.data;
  610.                 break;
  611.                 }
  612.             }
  613.         }
  614.  
  615.     if (chr & 0xFF) {    /* regular key */
  616.         chr &= 0xFF;
  617.         return(chr);
  618.         }
  619.     else    {
  620.         chr >>= 8;
  621.         chr &= 0xFF;
  622.         if (chr == 0xC8) chr = 133;
  623.         else if (chr >= 0xDB && chr <= 0xE4) {
  624.             J_Char(chr - 0xDB + 1);
  625.             goto again;
  626.             }
  627.         return(chr + 0x100);
  628.         }
  629.     }
  630.  
  631.  
  632. /* ------------------------------------------------------------ */
  633.  
  634. /* Check for a key press.  Return as KIsKey */
  635.  
  636. char
  637. JIsKey(void)
  638.     {
  639.     EVENT e;
  640.  
  641.     if (mac_len > 0) return('Y');
  642.  
  643.     m_nevent(&e);
  644.     switch (e.kind) {
  645.  
  646.     case E_ACTIV:
  647.         DNewDisplay();
  648.         DIncrDisplay();
  649.         VidCurOn();
  650.         break;
  651.  
  652.     case E_TERM:
  653.         mac_len = 1;
  654.         mac_ptr = (int *)(m.MacroBody);
  655.         m.MacroBody[0] = KEYQUIT;
  656.         
  657.     case E_KEY:
  658.         return('Y');
  659.         /*break;*/
  660.         }
  661.     return('N');
  662.     }
  663.  
  664.  
  665. /* ------------------------------------------------------------ */
  666.  
  667. /* Handle the HP95LX's menu key. */
  668.  
  669. void
  670. JMenu()
  671.     {
  672.     MENUDATA u;
  673.     EVENT e;
  674.     int which = 0;
  675.     FLAG isdone = FALSE;
  676.     FLAG ok = TRUE;
  677.  
  678.     uarg = 0;
  679.     menu_setup(&u, "Help\0Open\0PasteClip\0RegionToClip\0Save\0Quit\0",
  680.         6, 1, NULL, 0, NULL);
  681.  
  682.     VidCurOff();
  683.     menu_on(&u);
  684.  
  685.     while (!isdone) {
  686.         menu_dis(&u);
  687.         DJMenus(0);
  688.         m_event(&e);
  689.         switch (e.kind) {
  690.  
  691.         case E_ACTIV:
  692.             DNewDisplay();
  693.             DIncrDisplay();
  694.             VidCurOff();
  695.             break;
  696.  
  697.         case E_TERM:
  698.             mac_len = 1;
  699.             mac_ptr = (int *)(m.MacroBody);
  700.             m.MacroBody[0] = KEYQUIT;
  701.             isdone = TRUE;
  702.             break;
  703.         
  704.         case E_BREAK:
  705.             mac_len = 1;
  706.             mac_ptr = (int *)(m.MacroBody);
  707.             m.MacroBody[0] = KEYQUIT;
  708.             isdone = TRUE;
  709.             break;
  710.  
  711.         case E_KEY:
  712.             if (e.data == ESC || e.data == BEL) {
  713.                 which = -1;
  714.                 isdone = TRUE;
  715.                 }
  716.             else    {
  717.                 menu_key(&u, e.data, &which);
  718.                 if (which != -1) isdone = TRUE;
  719.                 }
  720.             break;
  721.             }
  722.         }
  723.  
  724.     menu_off(&u);
  725.     VidCurOn();
  726.  
  727.     switch (which) {
  728.  
  729.     case 0:
  730.         HHelp();
  731.         break;
  732.  
  733.     case 1:
  734.         FFileFind();
  735.         break;
  736.  
  737.     case 2:
  738.         ok = J_Paste();
  739.         break;
  740.  
  741.     case 3:
  742.         ok = J_Copy();
  743.         break;
  744.  
  745.     case 4:
  746.         FFileSave();
  747.         break;
  748.  
  749.     case 5:
  750.         MExit();
  751.         break;
  752.         }
  753.     if (!ok) JGetKey();
  754.     }
  755.  
  756.  
  757. /* ------------------------------------------------------------ */
  758.  
  759. /* Display a message. */
  760.  
  761. void
  762. JMsg(char *str)
  763.     {
  764.     m_lock();
  765.     message(str, strlen(str), "", 0);
  766.     JGetKey();
  767.     msg_off();
  768.     m_unlock();
  769.     }
  770.  
  771.  
  772. /* ------------------------------------------------------------ */
  773.  
  774. /* Cancel an exit operation. */
  775.  
  776. void
  777. JNoFini(void)
  778.     {
  779.     EVENT e;
  780.  
  781.     m_no_fini(&e);
  782.     }
  783.  
  784.  
  785. /* ------------------------------------------------------------ */
  786.  
  787. /* Pre-allocate the specified number of paragraphs.  This is a
  788. "placeholder" routine until I can fetch a current copy of the
  789. development tools.  Version 1.5? */
  790.  
  791. void
  792. JPreAlloc(unsigned paras)
  793.     {
  794.     }
  795.  
  796.  
  797. /* ------------------------------------------------------------ */
  798.  
  799. /* Switch input to the specified function key. */
  800.  
  801. void
  802. J_Char(int which)
  803.     {
  804.     SETTINGS s;
  805.  
  806.     m.MacroFK = which;
  807.     m_get_settings(&s, &m);
  808.  
  809.     if (which == m.MacroFK) {
  810.         mac_ptr = (int *)(m.MacroBody);
  811.         mac_len = m.MacroSize;
  812.         }
  813.     }
  814.  
  815.  
  816. /* ------------------------------------------------------------ */
  817.  
  818. /* Copy the region's contents into the buffer. Return True on
  819. success or False if the caller should wait for a keyboard press. */
  820.  
  821. FLAG
  822. J_Copy(void)
  823.     {
  824.     char chr;
  825.     FLAG isafter;
  826.  
  827.     if (m_open_cb() != 0) {
  828.         DEchoNM("can't open clipboard");
  829.         return(FALSE);
  830.         }
  831.     if (m_reset_cb("Freyja") != 0) {
  832.         DEchoNM("can't init clipboard");
  833.         m_close_cb();
  834.         return(FALSE);
  835.         }
  836.     m_new_rep("TEXT");
  837.  
  838. /* cycle over the region */
  839.  
  840.     if (isafter = BIsAfterMark(mark)) BMarkSwap(mark);
  841.     BMarkToPoint(cwin->point);
  842.     while (!BIsEnd() && BIsBeforeMark(mark)) {
  843.         chr = BGetCharAdv();
  844.         if (chr == NL) chr = '\xd';
  845.         m_cb_write(&chr, 1);
  846.         }
  847.     BPointToMark(cwin->point);
  848.     if (isafter) BMarkSwap(mark);
  849.  
  850.     m_fini_rep();
  851.     m_close_cb();
  852.     return(TRUE);
  853.     }
  854.  
  855.  
  856. /* ------------------------------------------------------------ */
  857.  
  858. /* Paste the clipboard's contents into the buffer. Return True on
  859. success or False if the caller should wait for a keyboard press. */
  860.  
  861. FLAG
  862. J_Paste(void)
  863.     {
  864.     int index;
  865.     int len;
  866.     char chr;
  867.     int cnt;
  868.  
  869.     if (m_open_cb() != 0) {
  870.         DEchoNM("can't open clipboard");
  871.         return(FALSE);
  872.         }
  873.     if (m_rep_index("TEXT", &index, &len) != 0) {
  874.         DEchoNM("nothing to paste");
  875.         m_close_cb();
  876.         return(FALSE);
  877.         }
  878.  
  879.     BMarkToPoint(mark);
  880.     for (cnt = 0; cnt < len; cnt++) {
  881.         m_cb_read(index, cnt, &chr, 1);
  882.         if (chr == '\xd') chr = NL;
  883.         if (!BInsChar(chr)) break;
  884.         }
  885.     m_close_cb();
  886.     return(TRUE);
  887.     }
  888.  
  889.  
  890. /* end of SMJAGUAR.C -- HP95LX (Jaguar) Commands and Support, System-Manager
  891. Compliant */
  892.